package pers.xiaojun.boot.module.system.dao.mapper.oauth2;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import pers.xiaojun.boot.module.system.dao.entity.oauth2.OAuth2RefreshTokenDO;

/**
 * 刷新令牌数据访问层
 *
 * @author xiaojun
 * @since 2025-10-16
 */
@Mapper
public interface OAuth2RefreshTokenMapper extends BaseMapper<OAuth2RefreshTokenDO> {


    /**
     * 根据刷新令牌获取刷新令牌信息
     *
     * @param refreshToken 刷新令牌
     * @return 刷新令牌实体
     */
    default OAuth2RefreshTokenDO selectByRefreshToken(String refreshToken) {
        return selectOne(new LambdaQueryWrapper<OAuth2RefreshTokenDO>()
                .eq(OAuth2RefreshTokenDO::getRefreshToken, refreshToken)
        );
    }

    /**
     * 根据刷新令牌删除刷新令牌数据
     *
     * @param refreshToken 刷新令牌
     */
    default void deleteByRefreshToken(String refreshToken) {
        delete(new LambdaQueryWrapper<OAuth2RefreshTokenDO>()
                .eq(OAuth2RefreshTokenDO::getRefreshToken, refreshToken)
        );
    }

}
